<?php $post = $this->get('post');?>
<div class="x-list-title">
	<table width="100%" border="0" height="100%">
	<tr>
		<td align="left">
			<h2><?php _e($post['name']);?></h2>
		</td>
		<td align="right">	
				<div class="x-list-options">
					<?php _e( tpl_search_form(baseUrl()."/Crm/Customer/Search", "#Crm/Customer/Search") );?>
					
					<div class="x-options-container">
						<a class="x-button"> Giao dịch <span>&#9660;</span></a>
						<div class="x-options">
							<a onclick="load_inframe('<?php _baseUrl();?>/Crm/Transaction/Add?redirect=<?php _e(rawurlencode('Crm/Customer/View?tab=transaction&ID='.$post['ID']) )?>&customer_id[]=<?php _e(get('ID'));?>',{ title: 'Giao dịch công ty'})" class="x-options-item">Giao dịch mới</a>
							<a onclick="location.href='mailto:'+$(this).find('textarea').get('value')" class="x-options-item">Gửi email
								<textarea style='display:none'><?php _e($post['name'])?> <<?php _e($post['email'])?>></textarea>
							</a>
							<a onclick="load_inframe('<?php _baseUrl();?>/Crm/Transaction/Sms?customer_id[]=<?php _e($post['ID'])?>',{auto_hidden:true,title: 'Gia dịch SMS',id: '<?php _e(getId())?>' })" class="x-options-item">Gửi SMS</a>
						</div>
					</div>				
					<div class="x-options-container">
						<a class="x-button"> Tác vụ khác <span>&#9660;</span></a>
						<div class="x-options">
							<a href="#Crm/Customer/Edit?ID=<?php _e(get('ID'));?>" class="x-options-item">Sửa công ty</a>
							<a onclick="module_delete('<?php _baseUrl();?>/Crm/Customer/Delete?ID[]=<?php _e(get('ID'));?>')" class="x-options-item">Xóa công ty</a>
							<a href="#Crm/Contact/Add?customer_id=<?php _e(get('ID'));?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=contact&ID=".$post['ID']))?>" class="x-options-item">Thêm liên hệ</a>
							<a href="#Crm/Contract/Add?customer_id=<?php _e(get('ID'));?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=contract&ID=".$post['ID']))?>" class="x-options-item">Thêm hợp đồng</a>
							<a href="#Crm/Customer/Add" class="x-options-item">Công ty mới</a>
						</div>
					</div>
				</div>
		</td>
	</tr>
	</table>	
</div>
<div class="tab-container" style="overflow: true;margin-top:-2px">
	<div class="tab-bar" style="border-right:1px solid #ccc">
		<a class="tab-link tab-link-first<?php if( !in_array(get('tab',''), array('contact','contract','transaction')) ) _e(' tab-link-active');?>" onclick="do_tab(this,1)">Thông tin</a>
		<a class="tab-link<?php if( get('tab','') == 'contact' ) _e(' tab-link-active');?>" onclick="do_tab(this,2)">Liên hệ</a>
		<a class="tab-link<?php if( get('tab','') == 'contract' ) _e(' tab-link-active');?>" onclick="do_tab(this,3)">Hợp đồng</a>
		<a class="tab-link<?php if( get('tab','') == 'transaction' ) _e(' tab-link-active');?>" onclick="do_tab(this,4)">Giao dịch</a>
		<span class="clear"></span>
	</div>
	<div class="tabs">	
		<div class="tab<?php if( !in_array(get('tab',''), array('contact','contract','transaction')) ) _e(' tab-active');?>">
			<div class="x-info-container">
				<table width="100%" border="0" class="x-info" cellspacing="0">
				<tr>
					<td colspan="4" align="right" class="x-info-top">
						<span class="tl">Thông tin chi chung</span>
						<span class="tr">Cập nhật lần cuối lúc <?php _e( show_date(DATETIME_FORMAT,$post['date_updated']) );?> bởi <?php _e(get_user_link( $post['updated_by_id'],$post['updated_by_name'],$post['updated_is_deleted']) );?></a></span>
					</td>
				</tr>
				<tr>
					<td class="x-info-label" nowrap="nowrap">
						Mã KH
					</td>
					<td class="x-info-content">
						<span class="code"><?php _e( $post['code'] );?></span>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Tên KH
					</td>
					<td class="x-info-content">
						<?php _e($post['name']);?>
					</td>	

				</tr>
				<tr>	
					<td class="x-info-label">
						Nhóm
					</td>
					<td class="x-info-content">
						<a href="#Crm/Customer?parent_id=<?php _e( $post['parent_id'] );?>">
						<?php _e( $post['parent_title'] );?>
						</a>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Ngành nghề
					</td>
					<td class="x-info-content">
						<a href="#Crm/Customer?trade_id=<?php _e( $post['trade_id'] );?>">	
						<?php _e( $post['trade_title'] );?>
						</a>	
					</td>
				</tr>
				<tr>	
					<td class="x-info-label">
						Quốc gia
					</td>
					<td class="x-info-content">
						<a href="#Crm/Customer?country_id=<?php _e( $post['country_id'] );?>">
						<?php _e( $post['country_title'] );?>
						</a>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Tỉnh/thành
					</td>
					<td class="x-info-content">
						<a href="#Crm/Customer?state_id=<?php _e( $post['state_id'] );?>">
						<?php _e( $post['state_title'] );?>		
						</a>
					</td>					
				</tr>
				<tr>	
					<td class="x-info-label">
						Quận/huyện
					</td>
					<td class="x-info-content">
						<a href="#Crm/Customer?district_id=<?php _e( $post['district_id'] );?>">
						<?php _e( $post['district_title'] );?>
						</a>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Trụ sở
					</td>
					<td class="x-info-content">
					<?php _e( $post['address'] );?>	
					</td>		
				</tr>
				<!--OTHER-->
				<tr>
					<td colspan="4" align="right" class="x-info-top">
						<span class="tl">Thông tin khác</span>
					</td>
				</tr>
				<tr>	
					<td class="x-info-label">
						Phone
					</td>
					<td class="x-info-content">
						<?php _e( $post['phone'] );?>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Fax
					</td>
					<td class="x-info-content">
					<?php _e( $post['fax'] );?>	
					</td>	
				</tr>
				<tr>	
					<td class="x-info-label">
						Email
					</td>
					<td class="x-info-content">
						<?php _e( show_email( $post['name'],$post['email']) );?>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Website
					</td>
					<td class="x-info-content">
					<?php _e( show_url($post['website']) );?>	
					</td>	
				</tr>
				
				<tr>	
					<td class="x-info-label">
						Sinh nhật công ty
					</td>
					<td class="x-info-content">
						<?php _e( show_date(DATE_FORMAT,$post['birthday']) );?>
					</td>
					<td class="x-info-label" nowrap="nowrap">
						Chăm sóc
					</td>
					<td class="x-info-content">
					<?php if( $this->get('care') ) _e( get_user_link($this->get('care')) );?>
					</td>	
				</tr>
				
				<tr>
					<td class="x-info-label x-info-label-last">
						Mô tả
					</td>
					<td colspan="3" class="x-info-content">
						<?php _e( $post['desc'] );?>
					</td>
				</tr>
				<tr>
					<td class="x-info-label x-info-label-last">
						Đính kèm
					</td>
					<td colspan="3" class="x-info-content">
					<?php $a=array();?>
					<?php foreach( $this->get('files') as $f ):?>
					<?php show_thumb( $f, baseUrl()."/Crm/Customer/File?ID={$f['ID']}");?>
					<?php endforeach;?>	
					</td>
				</tr>
			
			</table>
			</div>
		</div>
		<!--CONTACT-->
		<div class="tab<?php if( get('tab','') == 'contact' ) _e(' tab-active');?>" style="min-height:200px">
				<?php $posts = $this->get('contacts');?>
				<table width="100%" class="x-list" cellpadding="0" cellspacing="0">
				<tr>
					<th width="25" align="center">
						TT
					</th>
					<th width="90" align="center">
						Mã
					</th>
					<th align="center">
						Tên liên hệ
					</th>
					<th align="center" width="120">
						Chức vụ
					</th>
					<th align="center" width="100">
						Di động
					</th>
					<th align="center" width="180">
						Email
					</th>
					<th align="center" width="100">
						Chăm sóc
					</th>
					<th align="center" width="50" colspan="2">Tác vụ</th>
				</tr>	
				<?php if( count($posts) == 0 ):?>
				<tr>
				<td colspan="10" class="page">
					<div class="x-page">
						Không tìm thấy bản ghi nào
					</div>
				</td>
				</tr>
				<?php endif;?>
			<?php foreach( $posts as $k => $a ):?>
				<?php $vars = $this->get('vars');?>
				<tr>
				<td align="center">
					<?php _e($k+1);?>
				</td>
				<td align="center">
					<?php _e($a['code']);?>
				</td>				
				<td>
					<a href="#Crm/Contact/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['title'],30));?></a>
				</td>
				<td align="center">
					<?php _e($a['jobtitle']);?>
				</td>

				<td align="center">
					<?php _e($a['mobile']);?>
				</td>

				<td>
					<?php _e(show_email( $a['title'],$a['email']));?>
				</td>
					
				<td align="center">
					<?php _e(get_user_link( $a['care_by_id'], $a['care_by_name'], $a['care_is_deleted']  ) )?>
				</td>
				
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || $post['care_by_id'] == get_user_id() ):?>
					<a onclick="module_delete('<?php _baseUrl()?>/Crm/Contact/Delete?ID[]=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=contact&ID=".$post['ID']))?>')" class="x-delete"></a>
					<?php else:?>
					<a class="x-nodelete"></a>
					<?php endif;?>
				</td>
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || $post['care_by_id'] == get_user_id() ):?>
					<a href="#Crm/Contact/Edit?ID=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=contact&ID=".$post['ID']))?>" class="x-edit"></a>
					<?php else:?>
					<a class="x-noedit"></a>
					<?php endif;?>
				</td>	
				</tr>
				<?php endforeach;?>
				</table>
				<!-- END LIST-->		
		</div>
		<!--CONTRACTS-->
		<div class="tab<?php if( get('tab','') == 'contract' ) _e(' tab-active');?>" style="min-height:200px">
				<?php $posts = $this->get('contracts');?>
				<table width="100%" class="x-list" cellpadding="0" cellspacing="0">
				<tr>
					<th width="25" align="center">
						TT
					</th>
					<th width="190">
						Mã
					</th>
					<th align="center">
						Tên hợp đồng
					</th>
					<th align="center" width="100">
						Ngày ký
					</th>
					<th align="center" width="120">
						Loại
					</th>
					<th align="center" width="100">
						Giá trị
					</th>
					<th align="center" width="50" colspan="2">Tác vụ</th>
				</tr>	
				<?php if( count($posts) == 0 ):?>
				<tr>
				<td colspan="10" class="page">
					<div class="x-page">
						Không tìm thấy bản ghi nào
					</div>
				</td>
				</tr>
				<?php endif;?>
			<?php foreach( $posts as $k => $a ):?>
				<?php $vars = $this->get('vars');?>
				<tr>
				<td align="center">
					<?php _e($k+1);?>
				</td>
				<td align="center">
					<?php _e($a['code']);?>
				</td>				
				<td>
					<a href="#Crm/Contract/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['title'],30));?></a>
				</td>
				<td align="center">
					<?php _e(show_date(DATE_FORMAT,$a['date_reg']));?>
				</td>

				<td align="center">
					<?php _e($a['parent_title']);?>
				</td>

				<td align="right">
					<?php _e(show_number($a['value']));?> <?php _e($a['currency_symbol']);?>
				</td>
				
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || $post['care_by_id'] == get_user_id() ):?>
					<a onclick="module_delete('<?php _baseUrl()?>/Crm/Contract/Delete?ID[]=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/Customer/View?tab=contract&ID=".$post['ID']))?>')" class="x-delete"></a>
					<?php else:?>
					<a class="x-nodelete"></a>
					<?php endif;?>
				</td>
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || $post['care_by_id'] == get_user_id() ):?>
					<a href="#Crm/Contract/Edit?ID=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/Customer/View?tab=contract&ID=".$post['ID']))?>" class="x-edit"></a>
					<?php else:?>
					<a class="x-noedit"></a>
					<?php endif;?>
				</td>	
				</tr>
				<?php endforeach;?>
				</table>
				<!-- END LIST-->		
		</div>
		<!--TRANS-->
		<div class="tab<?php if( get('tab','') == 'transaction' ) _e(' tab-active');?>" style="min-height:200px">
				<?php $posts = $this->get('trans');?>
				<table width="100%" class="x-list" cellpadding="0" cellspacing="0">
				<tr>
					<th width="25" align="center">
						TT
					</th>
					<th align="center">
						Tiêu đề
					</th>
					<th width="90" align="center">
						Ngày
					</th>
					<th align="center" width="100">
						Loại giao dịch
					</th>
					<th align="center" width="270">
						Nội dung
					</th>
					<th align="center" width="100">
						Tạo bởi
					</th>
					<th align="center" width="100">
						Sửa bởi
					</th>
					<th align="center" width="50" colspan="2">Tác vụ</th>
				</tr>	
				<?php if( count($posts) == 0 ):?>
				<tr>
				<td colspan="10" class="page">
					<div class="x-page">
						Không tìm thấy bản ghi nào
					</div>
				</td>
				</tr>
				<?php endif;?>
			<?php foreach( $posts as $k => $a ):?>
				<?php $vars = $this->get('vars');?>
				<tr>
				<td align="center">
					<?php _e($k+1);?>
				</td>
				<td>
					<?php _e($a['title']);?>
				</td>				
				<td align="center">
					<?php _e(show_date(DATE_FORMAT,$a['date']));?>
				</td>

				<td align="center">
					<?php if( $a['parent_id'] !== '0' ):?>
					<?php _e($a['parent_title']);?>
					<?php else:?>
						Tự dộng
					<?php endif;?>
				</td>

				<td align="center">
					<?php _e($a['desc']);?>
				</td>
				<td align="center">
					<?php _e(get_user_link($a['created_by_id'],$a['created_by_name'],$a['created_is_deleted']));?>
				</td>

				<td align="center">
					<?php _e(get_user_link($a['updated_by_id'],$a['updated_by_name'],$a['updated_is_deleted']));?>
				</td>
				
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || 
						$post['care_by_id'] == get_user_id()  ):?>
					<a onclick="module_delete('<?php _baseUrl()?>/Crm/Transaction/Delete?ID[]=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=transaction&ID=".$post['ID']))?>')" class="x-delete"></a>
					<?php else:?>
					<a class="x-nodelete"></a>
					<?php endif;?>
				</td>
				<td align="center" width="25">
					<?php if( $this->hasRole('crm_admin') || $post['care_by_id'] == get_user_id() ):?>
					<a onclick="load_inframe('<?php _baseUrl()?>/Crm/Transaction/Edit?ID=<?php _e($a['ID'])?>&redirect=<?php _e(rawurlencode("Crm/customer/View?tab=transaction&ID=".$post['ID']))?>')" class="x-edit"></a>
					<?php else:?>
					<a class="x-noedit"></a>
					<?php endif;?>
				</td>	
				</tr>
				<?php endforeach;?>
				</table>
				<!-- END LIST-->		
		</div>		
	</div>